<?php
namespace Wap\Controller;
use Think\Controller;

class PayController extends Controller {
  
  
  public function newpay_notify()
	{
      if($_GET['donow']=="yes"){
         $danhao =$_REQUEST['out_trade_no'];//单号
			   $danrow = M('user_chongzhi')->where(array('ddanhao' => $danhao, 'dcode' => 1, ))->find(); //   $danrow = M('user_chongzhi')->where("ddanhao='$danhao' and dcode=1")->find();
			   if($danrow) {
			      $userid = $danrow['userid']; //充值人id
			      $djine = $danrow['djine'];  //充值金额
				  $user = M('user_list')->where(array('id' => $userid, ))->find();//充值人信息 //  $user = M('user_list')->where("id=$userid")->find();//充值人信息
			      M()->execute("update __USER_ZHANGHU__ set uqianchong=uqianchong+$djine,uchongzong=uchongzong+$djine where userid=$userid");
	              M()->execute("update __USER_CHONGZHI__ set dcode=2,djisuan=2 where ddanhao='$danhao'");
			      echo "success";
			   }
        exit;
        
      }
  }
  
  public function newpay_notify2()
	{
      if($_GET['donow']=="yes"){
         $danhao =$_REQUEST['out_trade_no'];//单号
			   $danrow = M('user_chongzhi')->where(array('ddanhao' => $danhao, 'dcode' => 1, ))->find(); //   $danrow = M('user_chongzhi')->where("ddanhao='$danhao' and dcode=1")->find();
			   if($danrow) {
			      $userid = $danrow['userid']; //充值人id
			      $djine = $danrow['djine'];  //充值金额
				  $user = M('user_list')->where(array('id' => $userid, ))->find();//充值人信息 //  $user = M('user_list')->where("id=$userid")->find();//充值人信息
			      M()->execute("update __USER_ZHANGHU__ set uqianchong=uqianchong+$djine,uchongzong=uchongzong+$djine where userid=$userid");
	              M()->execute("update __USER_CHONGZHI__ set dcode=2,djisuan=2 where ddanhao='$danhao'");
			      echo "success";
			   }
        exit;
        
      }
  }
	
	/**
	 * userid 用户id
	 * utype  用户分类 1用户拆红包 2代理佣金结算
	 * hzhifue 红包支付额
	 * userhbid 用户拆的红包id
	*/
	public function wxtixian($userid=0,$utype=2,$userhbid = 0, $zhuancun = false){
	    $userzhanghu = null;
		$jine = 0;
		if($utype==1){
			$userzhanghu = M('user_zhanghu')->where(array('userid' => $userid, ))->find(); //$userzhanghu = M('user_zhanghu')->where("userid=$userid")->find();
			$userhb = M('user_hb')->where(array('userid' => $userid, 'tcode' => 2, 'id' => $userhbid, ))->find(); //$userhb = M('user_hb')->where("userid=$userid and tcode=2 and id=$userhbid")->find();
			$jine = intval($userhb['hbe']);
			$hbid = intval($userhb['hbid']);
			$hb = M('hb')->where(array('id' => $hbid, ))->find(); //$hb = M('hb')->where("id=$hbid")->find();
			if( intval($userzhanghu['uqianchong']) < intval($hb['hzhifue']) || intval($userzhanghu['uqianchong']) <= 0){
			    die;
			}
			$hzhifue = intval($hb['hzhifue']);
		}
		if($utype==2){
			$jine = M('user_yongjin')->where(array('userid' => $userid, 'tcode' => 1, ))->sum('tixiane'); //$jine = M('user_yongjin')->where("userid=$userid and tcode=1")->sum('tixiane');
          	//return $jine;  
          $play = M('user_hb')->where(array('userid' => $userid))->find();
          	if(!$play){
            	return 6;
            }
		}
      if($utype==3){
			$userzhanghu = M('user_zhanghu')->where(array('userid' => $userid, ))->find(); //$userzhanghu = M('user_zhanghu')->where("userid=$userid")->find();
			$userhb = M('user_hb')->where(array('userid' => $userid, 'tcode' => 2, 'id' => $userhbid, ))->find(); //$userhb = M('user_hb')->where("userid=$userid and tcode=2 and id=$userhbid")->find();
			$jine = intval($userhb['hbe']);
			$hbid = intval($userhb['hbid']);
			$hb = M('hb')->where(array('id' => $hbid, ))->find(); //$hb = M('hb')->where("id=$hbid")->find();
			$hzhifue = intval($hb['hzhifue']);
		}
		$user = M('user_list')->where(array('id' => $userid, ))->find(); //$user = M('user_list')->where("id=$userid")->find();
		if(intval($jine) >= 10 && $user['ufacishu'] <= 99 ){
			/*开关开启*/
			if($zhuancun){
				// Todo: 加钱 // Done
			    M('UserZhanghu')->where(array('userid' => $userid,))->save(array('uqianchong' => $userzhanghu['uqianchong'] + intval($jine)));
				unset($data);
              $data['ddanhao'] = $danhao = '200' . date('YmdHis').rand(100000,999999);
              $data['userid'] = $userid;
              $data['djine'] = intval($jine);
              $data['dtime'] = time();
              $data['dcode'] = 2;
              $data['djisuan'] = 2;
              M('user_chongzhi')->add($data);
				// 减钱
				M()->execute("update __USER_ZHANGHU__ set uqianchong=uqianchong-$hzhifue where userid=$userid");
				M()->execute("update __USER_HB__ set tcode=1 where id=$userhbid");
				$yongjinma = rand(10000,99999);
				session('yongjinma',$yongjinma);
              	if($utype==1){
					$this->yongjin($user['utid'],$hzhifue,$yongjinma);
                }

				// ----

				//更新今天抽次数
				if( $user['ugengxin'] > strtotime(date("Ymd")) ) {
					M()->execute("update __USER_LIST__ set ufacishu=ufacishu+1 where id=$user[id]");
				} else {
					M('user_list')->save(array('id'=>$user['id'],'ufacishu'=>1,'ugengxin'=>time()));
				}
				return 2; //支付成功
			} else {
              	//20190125 zl 提现
              
                $txsetting = M('sys_config')->find();
                //插入提现记录
				$data['userid'] = $userid;
			    $data['tixiane'] = $jine;
			    $data['state'] = 1;
			    $data['ttime'] = time();
			    $insertId = M('user_tixian')->add($data);
                if (!$insertId) die;
                
              
                include './fastpay/Fast_Cofig.php';

				
                $pay_openid=$_COOKIE['pay_openid'];

                /*if(empty($pay_openid)){

                 $pay_openid=get_openid();
				return $pay_openid;
                $time_out=time()+3600;//一天后过期

                setcookie("pay_openid", $pay_openid, $time_out,"/");

                }*/

              	$data=array();
                $data['openid']=$pay_openid; //这个是第一步获取的openid
              	$data['amount']= $jine*0.01;//价格
              	$data['billno']=md5(time() . mt_rand(1,1000000));
              	$data['uid']= $userid;
              	$data['desc']=PAY_DESC."uid=".$userid;
              	$res=fast_pay($data);
                //return $res;
              	$res=json_decode($res,true);
                
              	if($res['result_code']=='SUCCESS'){
                  	M('user_tixian')->where('id='.$insertId)->setField('state',2);
					if($utype == 1){
				       M()->execute("update __USER_ZHANGHU__ set uqianchong=uqianchong-$hzhifue where userid=$userid");
					   M()->execute("update __USER_HB__ set tcode=1 where id=$userhbid");
					   $yongjinma = rand(10000,99999);
					   session('yongjinma',$yongjinma);
					   $this->yongjin($user['utid'],$hzhifue,$yongjinma);
					}
					if($utype==2){
			    	   M()->execute("update __USER_YONGJIN__ set tcode=2 where userid=$userid and tcode=1"); 
					   M()->execute("update __USER_ZHANGHU__ set uqianzheng=uqianzheng-$jine,uqianfa=uqianfa+$jine where userid=$userid");
					}
					//更新今天抽次数
				    if( $user['ugengxin'] > strtotime(date("Ymd")) ) {
					   M()->execute("update __USER_LIST__ set ufacishu=ufacishu+1 where id=$user[id]");
				    } else {
					   M('user_list')->save(array('id'=>$user['id'],'ufacishu'=>1,'ugengxin'=>time()));
				    }
                	return 2; //支付成功
                }else{
                	file_put_contents('my_tx_log',json_encode($output));
                    M('user_tixian')->where('id='.$insertId)->delete();
				    M('sys_log')->add(array('lbiaoshi'=>'微信付款','lcon'=>json_encode($res),'ltime'=>time()));
				    return 3; //支付失败
                }
              
              	//20181107 Tim 提现
				//$txsetting = M('sys_config')->find();
				//插入提现记录
				//$data['userid'] = $userid;
			    //$data['tixiane'] = $jine;
			    //$data['state'] = 1;
			    //$data['ttime'] = time();
			   // $insertId = M('user_tixian')->add($data);
			    //if (!$insertId) die;
              	// $lailu = 'http://hb115.zhongchou88.cn/';//来源【可选参数】
               // $post_data = array (
	           //     'mid' => $txsetting['txmid'], //在掌上零钱里面获取的uid
	           //     'jine' => $jine*0.01, //要请求发放的金额
	           //     'openid'=>$user['ubeiopenid'], //第二步获取的openid
	           //     'tixianid'=>$insertId, //本地的提现id【要求唯一】字符串类型的数字，最大长度11位数
	           //     'lailu' => $txsetting['cfaurl'], //可选参数
               // );
               // $mkey = md5($post_data['mid'].$post_data['jine'].$post_data['openid'].$txsetting['txkey']);

                //$post_data['mkey'] = $mkey;
                //$post_data['lx'] = 999;//保持默认
                //$url ='http://jfcms1.com/jieru.php';

                //$ch = curl_init();
                //curl_setopt($ch, CURLOPT_URL, $url);
               // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                // post数据
               // curl_setopt($ch, CURLOPT_POST, 1);
                // post的变量
               // curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

               // $output = curl_exec($ch);
              //  curl_close($ch);
               //var_dump($output);die;
              
         		//$output = json_decode($output,true);
				//if(isset($output['o']) && $output['o'] == 'yes'){
				//	M('user_tixian')->where('id='.$insertId)->setField('state',2);
				//	if($utype == 1){
				//       M()->execute("update __USER_ZHANGHU__ set uqianchong=uqianchong-$hzhifue where userid=$userid");
				//	   M()->execute("update __USER_HB__ set tcode=1 where id=$userhbid");
				//	   $yongjinma = rand(10000,99999);
				//	   session('yongjinma',$yongjinma);
				//	   $this->yongjin($user['utid'],$hzhifue,$yongjinma);
				//	}
				//	if($utype==2){
			    //	   M()->execute("update __USER_YONGJIN__ set tcode=2 where userid=$userid and tcode=1"); 
				//	   M()->execute("update __USER_ZHANGHU__ set uqianzheng=uqianzheng-$jine,uqianfa=uqianfa+$jine where userid=$userid");
				//	}
					//更新今天抽次数
				//    if( $user['ugengxin'] > strtotime(date("Ymd")) ) {
				//	   M()->execute("update __USER_LIST__ set ufacishu=ufacishu+1 where id=$user[id]");
				//    } else {
				//	   M('user_list')->save(array('id'=>$user['id'],'ufacishu'=>1,'ugengxin'=>time()));
				//    }
				//   return 2; //支付成功
				//} else {
                 // file_put_contents('my_tx_log',json_encode($output));
                 //   M('user_tixian')->where('id='.$insertId)->delete();
				//   M('sys_log')->add(array('lbiaoshi'=>'微信企业付款','lcon'=>json_encode($output),'ltime'=>time()));
				//   return 3; //支付失败
				//}
			}
		} else {
		    return 4;	//付款上限
		}
    }
	
	/**
	 * 计算三级佣金
	 * utid 用户推荐人ID
	 * yanzhengma 验证码
	 * ytype 佣金分类 1扫雷 2其它
	 */
	public function yongjin($utid = 0 , $jine = 0 ,$yongjinma = 0 , $ytype = 2){	
		if( $yongjinma == session('yongjinma') ){
			session('yanzhengmasanji',null);
			$utuser = M('user_list')->where(array('id' => $utid, ))->find(); //$utuser = M('user_list')->where("id=$utid")->find();
			$fenxiao = M('fenxiao')->find();
			if($fenxiao && $ytype == 2 && $utuser && $utid > 0){
				   if($fenxiao['fjine1'] > 0){
				   		$fenxiao1 = $fenxiao['fjine1']*$jine/100;//20181107 Tim 修改分佣按照百分比
				       M('user_yongjin')->add(array('userid'=>$utid, 'uchong'=>$jine, 'tixiane'=>$fenxiao1,'tjisuan'=>2,'ttime'=>time()));
					   M()->execute("update __USER_ZHANGHU__ set uqianzheng=uqianzheng+{$fenxiao1},
					   uzhengzong=uzhengzong+{$fenxiao1} where userid=$utid");
                       $this->checksong($utid);
				   }
				   $utid2 = intval($utuser['utid']);
				   $user2 = M('user_list')->where(array('id' => $utid2, ))->find(); //   $user2 = M('user_list')->where("id=$utid2")->find();
				   if($user2 && $utid2 > 0){
					   if($fenxiao['fjine2'] > 0){
					   		$fenxiao2 = $fenxiao['fjine2']*$jine/100;//20181107 Tim 修改分佣按照百分比
				          M('user_yongjin')->add(array('userid'=>$utid2, 'uchong'=>$jine, 'tixiane'=>$fenxiao2,'tjisuan'=>2,'ttime'=>time()));
						  M()->execute("update __USER_ZHANGHU__ set uqianzheng=uqianzheng+{$fenxiao2},
						  uzhengzong=uzhengzong+{$fenxiao2} where userid=$utid2");
                         $this->checksong($utid2);
					   }
					   $utid3 = intval($user2['utid']);
					   $user3 = M('user_list')->where(array('id' => $utid3, ))->find(); //   $user3 = M('user_list')->where("id=$utid3")->find();
					   if($user3 && $utid3 > 0){
						   if($fenxiao['fjine3'] > 0){
						   		$fenxiao3 = $fenxiao['fjine3']*$jine/100;//20181107 Tim 修改分佣按照百分比
				               M('user_yongjin')->add(array('userid'=>$utid3,'uchong'=>$jine, 'tixiane'=>$fenxiao3,'tjisuan'=>2,'ttime'=>time()));
							   M()->execute("update __USER_ZHANGHU__ set uqianzheng=uqianzheng+{$fenxiao3},
							   uzhengzong=uzhengzong+{$fenxiao3} where userid=$utid3");
                             	$this->checksong($utid3);
							}
                         	$utid4 = intval($user3['utid']);
						   $user4 = M('user_list')->where(array('id' => $utid4, ))->find(); //   $user4 = M('user_list')->where("id=$utid4")->find();
						   if($user4 && $utid4 > 0){
							   if($fenxiao['fjine4'] > 0){
							   		$fenxiao4 = $fenxiao['fjine4']*$jine/100;//20181107 Tim 修改分佣按照百分比
					               M('user_yongjin')->add(array('userid'=>$utid4,'uchong'=>$jine, 'tixiane'=>$fenxiao4,'tjisuan'=>2,'ttime'=>time()));
								   M()->execute("update __USER_ZHANGHU__ set uqianzheng=uqianzheng+{$fenxiao4},
								   uzhengzong=uzhengzong+{$fenxiao4} where userid=$utid4");
                                   $this->checksong($utid4);
								}
								$utid5 = intval($user4['utid']);
							   $user5 = M('user_list')->where(array('id' => $utid5, ))->find(); //   $user5 = M('user_list')->where("id=$utid5")->find();
							   if($user5 && $utid5 > 0){
								   if($fenxiao['fjine5'] > 0){
								   		$fenxiao5 = $fenxiao['fjine5']*$jine/100;//20181107 Tim 修改分佣按照百分比
						               M('user_yongjin')->add(array('userid'=>$utid5,'uchong'=>$jine, 'tixiane'=>$fenxiao5,'tjisuan'=>2,'ttime'=>time()));
									   M()->execute("update __USER_ZHANGHU__ set uqianzheng=uqianzheng+{$fenxiao5},
									   uzhengzong=uzhengzong+{$fenxiao5} where userid=$utid5");
                                       $this->checksong($utid5);
									}
									$utid6 = intval($user5['utid']);
								   $user6 = M('user_list')->where(array('id' => $utid6, ))->find(); //   $user6 = M('user_list')->where("id=$utid6")->find();
								   if($user6 && $utid6 > 0){
									   if($fenxiao['fjine6'] > 0){
									   		$fenxiao6 = $fenxiao['fjine6']*$jine/100;//20181107 Tim 修改分佣按照百分比
							               M('user_yongjin')->add(array('userid'=>$utid6,'uchong'=>$jine, 'tixiane'=>$fenxiao6,'tjisuan'=>2,'ttime'=>time()));
										   M()->execute("update __USER_ZHANGHU__ set uqianzheng=uqianzheng+{$fenxiao6},
										   uzhengzong=uzhengzong+{$fenxiao6} where userid=$utid6");
                                           $this->checksong($utid6);
										}
										$utid7 = intval($user6['utid']);
									   $user7 = M('user_list')->where(array('id' => $utid7, ))->find(); //   $user7 = M('user_list')->where("id=$utid7")->find();
									   if($user7 && $utid7 > 0){
										   if($fenxiao['fjine7'] > 0){
										   		$fenxiao7 = $fenxiao['fjine7']*$jine/100;//20181107 Tim 修改分佣按照百分比
								               M('user_yongjin')->add(array('userid'=>$utid7,'uchong'=>$jine, 'tixiane'=>$fenxiao7,'tjisuan'=>2,'ttime'=>time()));
											   M()->execute("update __USER_ZHANGHU__ set uqianzheng=uqianzheng+{$fenxiao7},
											   uzhengzong=uzhengzong+{$fenxiao7} where userid=$utid7");
                                               $this->checksong($utid7);
											}
									   }
								   }
							   }
						   }
					   }
				   }
			   
			}//三级分销
			//计算 充值佣金
			if($utid > 0 && $utuser){
			   //判断是否扣量
			   $sysconfig = M('sys_config')->find();
			   if($sysconfig['ckouliang'] > 0 ){
			       $tixiannum = M('user_yongjin')->where(array('userid' => $utid, ))->count(); //       $tixiannum = M('user_yongjin')->where("userid=$utid")->count();
			       if( ($tixiannum % 10) >= (10-$sysconfig['ckouliang']) ){
			          $data['tcode'] = $tcode = 4;
			       }
			   }
			   $yongjindengji = intval($utuser['uvip']);
			   $yongjinset = M('yongjin_set')->where(array('ydengji' => $yongjindengji, ))->find();	 //   $yongjinset = M('yongjin_set')->where("ydengji=$yongjindengji")->find();	
			   if($yongjinset){		   
			      $tixiane = $jine * 0.01 * intval($yongjinset['ybaifenbi']);
			      $data['userid'] = $utid;
			      $data['uchong'] = $jine;
			      $data['tixiane'] = $tixiane;
			      $data['tjisuan'] = 2;
			      $data['ttime'] = time();
			      M('user_yongjin')->add($data);
			      unset($data);
			      //更新账户
			      if(intval($tcode) != 4 ) {
				     M()->execute("update __USER_ZHANGHU__ set uqianzheng=uqianzheng+$tixiane,
					 uzhengzong=uzhengzong+$tixiane where userid=$utid");
			      }
			   }
			   //自动升级代理
			   $yongjinset = M('yongjin_set')->where(array('ydengji' => ($yongjindengji+1), ))->find();	 //   $yongjinset = M('yongjin_set')->where("ydengji=($yongjindengji+1)")->find();	
			   if($yongjinset){
				   $tixiane = M('user_yongjin')->where(array('userid' => $utid, 'tcode' => array('in', '1,2'), ))->sum('uchong');	 //   $tixiane = M('user_yongjin')->where("userid=$utid and tcode in(1,2)")->sum('uchong');	
				   if($tixiane >= $yongjinset['yjine']) {
					   M()->execute("update __USER_LIST__ set uvip=uvip+1 where id=$utid");
				   }
			   }
			}
		} //验证码	
	}
	
  	public function checksong($uid){
    	
    	$zong = M("user_yongjin")->where(array("userid" => $uid))->sum("tixiane");
      	$sys = M('sys_config')->find();
      	if($sys['man1'] > 0 && $zong >= $sys['man1']){
        	$info = M("user_chongzhi")->where(array("userid"=> $uid, 'song'=> 1))->find();
          	if(!$info){
            	$data = array();
              	$data['ddanhao'] = '111' . date('YmdHis').rand(100000,999999);
                $data['userid'] = $uid;
                $data['djine'] = intval($sys['song1']);
                $data['dtime'] = time();
                $data['dcode'] = 2;
                $data['djisuan'] = 2;
                $data['song'] = 1;
                $data['type'] = 3;
                M('user_chongzhi')->add($data);
                $userzhanghu = M('UserZhanghu')->where(array('userid' => $uid))->find();
                M('UserZhanghu')->where(array('userid' => $uid))->save(array('uqianchong' => $userzhanghu['uqianchong'] + intval($sys['song1'])));
            }
        }
      
      if($sys['man2'] > 0 && $zong >= $sys['man2']){
        	$info = M("user_chongzhi")->where(array("userid"=> $uid, 'song'=> 2))->find();
          	if(!$info){
            	$data = array();
              	$data['ddanhao'] = '222' . date('YmdHis').rand(100000,999999);
                $data['userid'] = $uid;
                $data['djine'] = intval($sys['song2']);
                $data['dtime'] = time();
                $data['dcode'] = 2;
                $data['djisuan'] = 2;
                $data['song'] = 2;
                $data['type'] = 3;
                M('user_chongzhi')->add($data);
                $userzhanghu = M('UserZhanghu')->where(array('userid' => $uid))->find();
                M('UserZhanghu')->where(array('userid' => $uid,))->save(array('uqianchong' => $userzhanghu['uqianchong'] + intval($sys['song2'])));
             
            }
        }
      
      if($sys['man3'] > 0 && $zong >= $sys['man3']){
        	$info = M("user_chongzhi")->where(array("userid"=> $uid, 'song'=> 3))->find();
          	if(!$info){
            	$data = array();
              	$data['ddanhao'] = '333' . date('YmdHis').rand(100000,999999);
                $data['userid'] = $uid;
                $data['djine'] = intval($sys['song3']);
                $data['dtime'] = time();
                $data['dcode'] = 2;
                $data['djisuan'] = 2;
                $data['song'] = 3;
                $data['type'] = 3;
                M('user_chongzhi')->add($data);
                $userzhanghu = M('UserZhanghu')->where(array('userid' => $uid))->find();
                M('UserZhanghu')->where(array('userid' => $uid,))->save(array('uqianchong' => $userzhanghu['uqianchong'] + intval($sys['song3'])));             
            }
        }
      
      return '1';
    }
  
	/**
	 * 用户扫雷
	 * userid 领用户id 
	 * lingid 用户领到的红包id
	*/
	public function saolei($userid=0,$lingid=0){
		    $user = M()->table('__USER_LIST__ a')->join('__USER_ZHANGHU__ b on a.id=b.userid')->where("a.id=$userid")
			           ->field('a.uopenid,b.uqianchong')->find();
			$linghb = M()->table('__SAOLEI_LINGHB__ a')->join('__SAOLEI_USERFALIST__ b on a.hblistid=b.id')
			             ->join('__SAOLEI_USERFA__ c on b.faid=c.id')->where("a.id=$lingid and a.hcode=1")
			             ->field('a.hbe,a.userid,c.hzhifue,a.hblistid')->find();
			$jine = intval($linghb['hbe']);

			if(!$linghb) die;
			if($userid != $linghb['userid']) die;
			if($user['uqianchong'] < $linghb['hzhifue'] || $user['uqianchong']==0 ) die;
			
				//20181107 Tim 提现
				$txsetting = M('sys_config')->find();
				//插入提现记录
				$data['userid'] = $userid;
			    $data['tixiane'] = $jine;
			    $data['state'] = 1;
			    $data['ttime'] = time();
			    $insertId = M('user_tixian')->add($data);
			    if (!$insertId) die;
              	// $lailu = 'http://hb115.zhongchou88.cn/';//来源【可选参数】
                $post_data = array (
	                'mid' => $txsetting['txmid'], //在掌上零钱里面获取的uid
	                'jine' => $jine*0.01, //要请求发放的金额
	                'openid'=>session("newopenid"), //第二步获取的openid
	                'tixianid'=>$insertId, //本地的提现id【要求唯一】字符串类型的数字，最大长度11位数
	                'lailu' => $txsetting['cfaurl'], //可选参数
                );
                $mkey = md5($post_data['mid'].$post_data['jine'].$post_data['openid'].$txsetting['txkey']);

                $post_data['mkey'] = $mkey;
                $post_data['lx'] = 999;//保持默认
                $url ='http://jfcms1.com/jieru.php';

                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                // post数据
                curl_setopt($ch, CURLOPT_POST, 1);
                // post的变量
                curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

                $output = curl_exec($ch);
                curl_close($ch);
      			$output = json_decode($output,true);
			if(isset($output['o']) && $output['o'] == 'yes'){
				M()->execute("update __SAOLEI_LINGHB__ set hcode=2 where id=$lingid");
                M('user_tixian')->where('id='.$insertId)->setField('state',2);
			} else {
              	M('user_tixian')->where('id='.$insertId)->delete();
				M()->execute("update __USER_ZHANGHU__ set uqianchong=uqianchong+$linghb[hbe] where userid=$userid");
				M()->execute("update __SAOLEI_LINGHB__ set hcode=3 where id=$lingid");
				M('sys_log')->add(array('lbiaoshi'=>'微信企业付款','lcon'=>$postXml.$responseXml,'ltime'=>time()));
			}
			M()->execute("update __SAOLEI_USERFALIST__ set hcode=2 where id=$linghb[hblistid]");
			
    }	
}
?>